/**
 * 
 */
package edu.wpi.cs509.messages.server;

import edu.wpi.cs509.messages.MsgBc;
import edu.wpi.cs509.representation.GameID;

/**
 * This class implements the join-game message.
 * @author sparadis
 *
 */
public class MsgJoinGame extends MsgServerContext {

	/**
	 * serializable version number
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * gId: id of game to join
	 */
	protected GameID gId;
	
	/**
	 * Constructor
	 * @param gId - id of game to join.
	 */
	public MsgJoinGame(GameID gId) {
		this.gId = gId;
	}

	/**
	 * Join the game.
	 * @return MsgBc - the reply to the client.
	 */
	@Override
	public MsgBc doExecuteAndGetReply() {
		
		//Call the server to join the game
		getServer().joinGame(gId, getConnection());
		
		// The server's joinGame function owns sending all replies
		// since both the joining player and the opponent must be 
		// notified 
		// Thus, return null here to stop the auto-reply code. 
		return null;
	}

}